package com.dcits.idea.processor;

import freemarker.template.Template;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.io.Writer;

/**
 * @Author tangmqb DCITS
 * @DATE 2021/11/4 14:52
 * @Version 1.0.0
 */
public abstract class FreemarkerProcessor implements Processor {
    protected abstract Object getModel(SourceDataNode sourceDataNode);

    protected abstract Template getTemplate() throws IOException;

    protected abstract Writer getWriter(SourceDataNode sourceDataNode) throws FileNotFoundException, UnsupportedEncodingException, Exception;
    @Override
    public final void process(SourceDataNode sourceDataNode) throws Exception {
        Template template = getTemplate();
        Writer writer = getWriter(sourceDataNode);
        Object model = getModel(sourceDataNode);
        template.process(model,writer);
    }
}
